import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import junit.framework.TestCase;

/**
 *  To test the HashTable Class
 * @author Matthew Dye
 *
 * @param <K>
 */
public class HashTableTest extends TestCase {
	Scanner scan;
	ArrayList<String> keys;
	ArrayList<Integer> vals;
	
	HashNode<String,Integer>[] arr, arr2;
	MSDRadixSorter<Integer> rs;
	HashTable<String,Integer> ht;
	
	public void testAdd() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		ht = new HashTable<String, Integer>(new JavaHash());
		for (int i = 0; i < keys.size(); i++){
			ht.add(keys.get(i), vals.get(i));
		}
		
		assertFalse(ht.contains("Hello World"));
		assertTrue(ht.contains("SMITH"));
	}
	
	public void testRemove() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		ht = new HashTable<String, Integer>(new JavaHash());
		for (int i = 0; i < keys.size(); i++){
			ht.add(keys.get(i), vals.get(i));
		}
		assertTrue(ht.contains("SMITH"));
		ht.remove("SMITH");
		assertFalse(ht.contains("SMITH"));
	}
	
	public void testGet() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		ht = new HashTable<String, Integer>(new JavaHash());
		for (int i = 0; i < keys.size(); i++){
			ht.add(keys.get(i), vals.get(i));
		}
		int valOut = ht.get("SMITH");
		assertTrue(valOut == vals.get(0));
	}
}
